package com.excellence.controller;

import com.excellence.datamodel.Result;
import com.excellence.pojo.Crop;
import com.excellence.pojo.Massif;
import com.excellence.service.CropService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 沈秉璋
 * @ClassName CropController
 * @Description TODO
 * @date 2024/4/8 11:40
 * @Version 1.0
 */

@Slf4j
@RestController
@RequestMapping("/api/crop")
public class CropController {
    @Autowired
    private CropService cropService;

    @DeleteMapping("/deleteByPrimaryKey")
    Result deleteByPrimaryKey(Long id){
        int res = cropService.deleteByPrimaryKey(id);
        return Result.success(res);
    }
    @PostMapping("/insert")
    Result insert(@RequestBody Crop record){
        int res = cropService.insert(record);
        return Result.success(res);
    }

    @PostMapping("/insertSelective")
    Result insertSelective(Crop record){
        int res = cropService.insertSelective(record);
        return Result.success(res);
    }

    @GetMapping("/selectByMassifId")
    Result selectByPrimaryKey(Integer massifId){
        List<Crop> crops = cropService.selectByMassifId(massifId);
        return Result.success(crops);
    }

    @GetMapping("/selectAll")
    Result selectAll(){
        List<Crop> res = cropService.selectAll();
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKeySelective")
    Result updateByPrimaryKeySelective(Crop record){
        int res = cropService.updateByPrimaryKeySelective(record);
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKey")
    Result updateByPrimaryKey(Crop record){
        int res = cropService.updateByPrimaryKey(record);
        return Result.success(res);
    }

}
